package proto

import (
	"regexp"
	D "websocket_apn/define"
	"websocket_apn/log"
)

/*
71 AB 00 00 02 8F 00 00 79 23 00 00 02 D4 07 01 81 E2 08 00
12 F4 04 0A 10 08 00 10 82 80 8A DA FC 32 18 82 E7 81 DA FC 32
12 0A 08 C3 9A 0C 10 05 18 00 20 00
12 0A 08 C2 9A 0C 10 05 18 00 20 00
12 0A 08 C1 9A 0C 10 05 18 00 20 00
12 0A 08 84 B5 18 10 05 18 00 20 00
12 0A 08 82 B5 18 10 05 18 00 20 00
12 0A 08 83 B5 18 10 05 18 00 20 00
12 0A 08 C4 9A 0C 10 05 18 00 20 00
12 0A 08 81 B5 18 10 05 18 00 20 00
12 0A 08 C1 CF 24 10 06 18 00 20 00
12 0A 08 C3 CF 24 10 00 18 00 20 00
12 0A 08 C2 CF 24 10 00 18 00 20 00
12 0A 08 C5 CF 24 10 00 18 00 20 00
12 0A 08 C4 CF 24 10 00 18 00 20 00
12 0A 08 D1 E8 0C 10 01 18 00 20 00
12 0A 08 91 83 19 10 01 18 00 20 00
12 0A 08 D1 9D 25 10 01 18 00 20 00
12 0A 08 A1 8D 06 10 0F 18 00 20 00
12 0A 08 E4 A7 12 10 05 18 00 20 00
12 0A 08 A3 8D 06 10 0F 18 00 20 00
12 0A 08 A2 8D 06 10 0F 18 00 20 00
12 0A 08 A4 C2 1E 10 0F 18 00 20 00
12 0A 08 A3 C2 1E 10 0F 18 00 20 00
12 0A 08 A4 8D 06 10 0F 18 00 20 00
12 0A 08 E1 A7 12 10 05 18 00 20 00
12 0A 08 A2 C2 1E 10 0E 18 00 20 00
12 0A 08 E2 A7 12 10 05 18 00 20 00
12 0A 08 A1 C2 1E 10 05 18 00 20 00
12 0A 08 E3 A7 12 10 05 18 00 20 00
12 0A 08 B1 DB 06 10 02 18 00 20 00
12 0A 08 F1 F5 12 10 01 18 00 20 00
12 0A 08 B1 90 1F 10 01 18 00 20 00
12 0A 08 F1 AA 2B 10 01 18 00 20 00

1A 0B 08 B9 FB E2 04 10 03 18 00 20 00
1A 0B 08 9B FB E2 04 10 03 18 00 20 00
1A 0B 08 DD C9 E3 04 10 00 18 00 20 00
1A 0B 08 BF C9 E3 04 10 00 18 00 20 00
1A 0B 08 B0 FB E2 04 10 03 18 00 20 00
1A 0B 08 D3 C9 E3 04 10 00 18 00 20 00
1A 0B 08 B5 C9 E3 04 10 00 18 00 20 00
1A 0B 08 D7 FB E2 04 10 03 18 00 20 00
1A 0B 08 C9 C9 E3 04 10 00 18 00 20 00
1A 0B 08 EB FB E2 04 10 00 18 00 20 00
1A 0B 08 AB C9 E3 04 10 00 18 00 20 00
1A 0B 08 CD FB E2 04 10 03 18 00 20 00
1A 0B 08 CE FB E2 04 10 03 18 00 20 00
1A 0B 08 AF FB E2 04 10 03 18 00 20 00
1A 10 08 E1 FB E2 04 10 00 18 D3 F8 D9 DB FC 32 20 01
1A 0B 08 C3 FB E2 04 10 01 18 00 20 00
1A 0B 08 A5 FB E2 04 10 03 18 00 20 00


18 00 20 00


升级
71 AB 00 00 00 17 00 03 86 5D 00 00 02 D4 07 01 81 E2 08 EB FB E2 04

*/

// 解析神躯信息
func ParaShenQuInfo(dataBytes []byte) D.ShenQuInfo {
	allInfo := D.ShenQuInfo{}
	data := BytesToHexStr(dataBytes)
	// 					                              1 id          2 次数             3 剩余时间
	re := regexp.MustCompile(`12[0-9A-F]{2}08([0-9A-F]{6})10([0-9A-F]{2})18(00|[0-9A-F]{12})20`)
	res := re.FindAllStringSubmatch(data, -1)
	for _, regRes := range res {
		info := D.ShenQuDetailInfo{
			ID:      regRes[1],                      //ID
			Count:   OneByteHexStrToByte(regRes[2]), //次数
			EndTime: ParaHexStrToTimeMs(regRes[3]),  //活动结束时间
		}
		allInfo.A = append(allInfo.A, info)
	}
	// 					                              1 id          2 次数             3 剩余时间
	re0 := regexp.MustCompile(`1A[0-9A-F]{2}08([0-9A-F]{8})10([0-9A-F]{2})18(00|[0-9A-F]{12})20`)
	res0 := re0.FindAllStringSubmatch(data, -1)
	for _, regRes := range res0 {
		info := D.ShenQuDetailInfo{
			ID:      regRes[1],                      //ID
			Count:   OneByteHexStrToByte(regRes[2]), //次数
			EndTime: ParaHexStrToTimeMs(regRes[3]),  //活动结束时间
		}
		allInfo.B = append(allInfo.B, info)
	}
	if len(allInfo.A) == 0 || len(allInfo.B) == 0 {
		log.Errorf("解析数据失败-%s", data)
	}
	return allInfo
}
